from model.blocks.Ground import Ground
from model.blocks.Lava import Lava
from model.blocks.Wall import Wall
from model.events.Door import Door
from model.events.Event import Event
from model.events.Gem import Gem
from model.events.Key import Key
from model.events.Medicine import Medicine
from model.events.Monster import Monster, monster_data
from model.events.Stairs import Stairs
from view.blockImgs.GroundImg import GroundImg
from view.blockImgs.LavaImg import LavaImg
from view.blockImgs.WallImg import WallImg



def a_line_block(number, img_type, size):
    return [[number, img_type]] * size


def draw_line(line_info):
    res = []
    for block in line_info:
        res = res + a_line_block(block[0], block[1], block[2])
    return res


head = [[1, 3, 1], [0, -1, 5], [1, 3, 1]]


class GameMap:
    current_floor = 0
    game_map = [[0] * 15 for i in range(21)]
    game_event = [[Event()] * 15 for i in range(21)]
    game_event[15][7] = Stairs(x_position=15, y_position=7, direction=1, location=[15, 7])
    game_event[18][7] = Door(x_position=18, y_position=7, color="yellow")

    map_data_dictionary = [[Ground, GroundImg],
                           [Wall, WallImg],
                           [Lava, LavaImg],
                           ]

    test_floor = [draw_line([[1, 3, 21]])] * 5 + [draw_line([[0, -1, 21]])] * 5 + [draw_line([[1, 3, 21]])] * 5

    @staticmethod
    def test_floor_event():
        GameMap.game_event[13][1] = Stairs(x_position=13, y_position=1, direction=1, location=[7, 13])


    first_floor = [
        draw_line([[1, 3, 21]]),
        draw_line(head + [[1, 2, 6], [0, -1, 1], [1, 2, 1], [1, 2, 5], [1, 3, 1]]),
        draw_line(head + [[1, 2, 2], [0, -1, 3], [1, 2, 1], [0, -1, 1], [1, 2, 1], [0, -1, 3], [1, 2, 2],
                          [1, 3, 1]]),
        draw_line(head + [[1, 2, 1], [0, -1, 11], [1, 2, 1], [1, 3, 1]]),
        draw_line(head + [[1, 2, 1], [0, -1, 11], [1, 2, 1], [1, 3, 1]]),
        draw_line(head + [[1, 2, 1], [0, -1, 11], [1, 2, 1], [1, 3, 1]]),
        draw_line(head + [[1, 2, 1], [0, -1, 11], [1, 2, 1], [1, 3, 1]]),
        draw_line([[1, 3, 7], [1, 2, 1], [0, -1, 11], [1, 2, 1], [1, 3, 1]]),
        draw_line(head + [[1, 2, 1], [0, -1, 11], [1, 2, 1], [1, 3, 1]]),
        draw_line(head + [[1, 2, 6], [0, -1, 1], [1, 2, 6], [1, 3, 1]]),
        draw_line(head + [[1, 2, 2], [2, -1, 1], [1, 2, 1], [2, -1, 1], [1, 2, 1], [0, -1, 1], [1, 2, 1], [2, -1, 1],
                          [1, 2, 1],
                          [2, -1, 1], [1, 2, 2], [1, 3, 1]]),
        draw_line(head + [[1, 2, 1], [2, -1, 4], [1, 2, 1], [0, -1, 1], [1, 2, 1], [2, -1, 4], [1, 2, 1], [1, 3, 1]]),
        draw_line(head + [[2, -1, 5], [1, 2, 1], [0, -1, 1], [1, 2, 1], [2, -1, 5], [1, 3, 1]]),
        draw_line(head + [[2, -1, 5], [1, 2, 1], [0, -1, 1], [1, 2, 1], [2, -1, 5], [1, 3, 1]]),
        draw_line([[1, 3, 21]]),
    ]

    @staticmethod
    def first_floor_event():
        GameMap.game_event[13][1] = Stairs(x_position=13, y_position=1, direction=1, location=[8, 13])
        GameMap.game_event[13][2] = Key(x_position=13, y_position=2, color="yellow")
        GameMap.game_event[13][9] = Door(x_position=13, y_position=9, color="yellow")
        GameMap.game_event[12][5] = Monster(x_position=12, y_position=5, monster_attribute=monster_data[2])
        GameMap.game_event[12][8] = Monster(x_position=12, y_position=8, monster_attribute=monster_data[3])
        GameMap.game_event[14][6] = Monster(x_position=14, y_position=6, monster_attribute=monster_data[2])
        GameMap.game_event[18][4] = Monster(x_position=18, y_position=4, monster_attribute=monster_data[3])
        GameMap.game_event[8][4] = Monster(x_position=8, y_position=4, monster_attribute=monster_data[3])
        GameMap.game_event[10][6] = Monster(x_position=10, y_position=6, monster_attribute=monster_data[2])
        GameMap.game_event[9][4] = Monster(x_position=9, y_position=4, monster_attribute=monster_data[3])
       # GameMap.game_event[13][2] = Key(x_position=13, y_position=2, color="purple")

    second_floor = [
        draw_line([[1, 3, 21]]),
        draw_line(head + [[0, -1, 9], [1, 2, 4], [1, 3, 1]]),
        draw_line(head + [[1, 2, 2], [0, -1, 2], [0, -1, 1], [1, 2, 1], [0, -1, 1], [1, 2, 1], [0, -1, 3], [1, 2, 2],
                          [1, 3, 1]]),
        draw_line(head + [[1, 2, 0], [0, -1, 5], [1, 2, 1], [0, -1, 1], [1, 2, 1], [0, -1, 4], [1, 2, 1], [1, 3, 1]]),
        draw_line(head + [[1, 2, 0], [0, -1, 3], [1, 2, 3], [0, -1, 1], [1, 2, 3], [0, -1, 2], [1, 2, 1], [1, 3, 1]]),
        draw_line(head + [[1, 2, 0], [0, -1, 12], [1, 2, 1], [1, 3, 1]]),

        draw_line(head + [[1, 2, 0], [0, -1, 2], [1, 2, 4], [0, -1, 1], [1, 2, 4], [0, -1, 2], [1, 3, 1]]),
        draw_line([[1, 3, 7],[0, -1, 2], [1, 2, 1], [0, -1, 2], [1, 2, 1], [0, -1, 1], [1, 2, 1], [0, -1, 2], [1, 2, 1],
                          [0, -1, 2], [1, 3, 1]]),
        draw_line(head+[[0, -1, 2], [1, 2, 1], [0, -1, 2], [1, 2, 1], [0, -1, 1], [1, 2, 1], [0, -1, 2], [1, 2, 1],
                          [0, -1, 2], [1, 3, 1]]),
        draw_line(head + [[0, -1, 2], [1, 2, 1], [0, -1, 2], [1, 2, 1], [0, -1, 1], [1, 2, 1], [0, -1, 2], [1, 2, 1],
                          [0, -1, 2], [1, 3, 1]]),
        draw_line(head + [[0, -1, 2], [1, 2, 1], [0, -1, 2], [1, 2, 1], [0, -1, 1], [1, 2, 1], [0, -1, 2], [1, 2, 1],
                          [0, -1, 2], [1, 3, 1]]),
        draw_line(head + [[0, -1, 2], [1, 2, 2], [0, -1, 5], [1, 2, 2], [0, -1, 2], [1, 3, 1]]),
        draw_line(head + [[0, -1, 3], [1, 2, 3], [0, -1, 1], [1, 2, 3], [0, -1, 3], [1, 3, 1]]),
        draw_line(head + [ [0, -1, 12], [1, 2, 1], [1, 3, 1]]),
        draw_line([[1, 3, 21]]),
    ]

    @staticmethod
    def second_floor_event():
        GameMap.game_event[10][5] = Door(x_position=10, y_position=5, color="purple")
        GameMap.game_event[16][5] = Door(x_position=16, y_position=5, color="purple")
        GameMap.game_event[13][2] = Door(x_position=13, y_position=2, color="yellow")
        GameMap.game_event[13][10] = Door(x_position=13, y_position=10, color="yellow")
        GameMap.game_event[11][5] = Monster(x_position=11, y_position=5, monster_attribute=monster_data[3])
        GameMap.game_event[15][5] = Monster(x_position=15, y_position=5, monster_attribute=monster_data[3])
        GameMap.game_event[13][3] = Monster(x_position=13, y_position=3, monster_attribute=monster_data[2])

        GameMap.game_event[10][7] = Medicine(x_position=10, y_position=7, color="purple")
        GameMap.game_event[11][7] = Medicine(x_position=11, y_position=7, color="red")
        GameMap.game_event[15][7] = Medicine(x_position=15, y_position=7, color="purple")
        GameMap.game_event[16][7] = Medicine(x_position=16, y_position=7, color="red")

        GameMap.game_event[10][8] = Gem(x_position=10, y_position=8,color="purple")
        GameMap.game_event[11][8] = Gem(x_position=11, y_position=8,color="red")
        GameMap.game_event[10][9] = Gem(x_position=10, y_position=9,color="purple")
        GameMap.game_event[11][9] = Gem(x_position=11, y_position=9,color="red")
        GameMap.game_event[15][8] = Gem(x_position=15, y_position=8, color="purple")
        GameMap.game_event[16][8] = Gem(x_position=16, y_position=8, color="red")
        GameMap.game_event[15][9] = Gem(x_position=15, y_position=9, color="purple")
        GameMap.game_event[16][9] = Gem(x_position=16, y_position=9, color="red")

        GameMap.game_event[13][8] = Key(x_position=13, y_position=8, color="yellow")
        GameMap.game_event[13][4] = Key(x_position=13, y_position=4, color="purple")

        GameMap.game_event[7][13] = Stairs(x_position=7, y_position=13, direction=-1, location=[13, 13])
        GameMap.game_event[13][5] = Stairs(x_position=13, y_position=5, direction=1, location=[9, 11])
    third_floor = [
        draw_line([[1, 3, 21]]),  # 1

        draw_line(head + [[1, 2, 7], [1, 2, 6], [1, 3, 1]]),  # 2开始
        draw_line(head + [[0, -1, 3], [1, 2, 1], [0, -1, 1], [1, 2, 1], [0, -1, 1], [0, -1, 5], [1, 2, 1],
                          [1, 3, 1]]),  # 3
        draw_line(head + [[0, -1, 1], [1, 2, 1], [0, -1, 3], [0, -1, 7], [1, 2, 1], [1, 3, 1]]),  # 4
        draw_line(head + [[1, 2, 11], [0, -1, 1], [1, 2, 1], [1, 3, 1]]),  # 5
        draw_line(head + [[0, -1, 5], [1, 2, 1], [0, -1, 6], [1, 2, 1], [1, 3, 1]]),  # 6
        draw_line(head + [[1, 2, 4], [0, -1, 1], [1, 2, 1], [0, -1, 6], [1, 2, 1], [1, 3, 1]]),  # 7
        draw_line(head + [[0, -1, 5], [1, 2, 6], [0, -1, 1], [1, 2, 1], [1, 3, 1]]),  # 8
        draw_line([[1, 3, 7], [1, 2, 0], [0, -1, 5], [1, 2, 1], [0, -1, 7], [1, 3, 1]]),  # 9
        draw_line(head + [[0, -1, 1], [1, 2, 5], [0, -1, 2], [1, 2, 4], [0, -1, 1], [1, 3, 1]]),  # 10
        draw_line(head + [[0, -1, 5], [1, 2, 1], [0, -1, 3], [1, 2, 0], [0, -1, 2], [1, 2, 1], [0, -1, 1],
                          [1, 3, 1]]),  # 11
        draw_line(head + [[0, -1, 5], [1, 2, 1], [0, -1, 2], [1, 2, 1], [0, -1, 2], [1, 2, 1], [0, -1, 1], [1, 3, 1]]),
        # 12
        draw_line(head + [[0, -1, 1], [1, 2, 6], [0, -1, 1], [1, 2, 3], [1, 2, 1], [0, -1, 1], [1, 3, 1]]),  # 13
        draw_line(head + [[0, -1, 13], [1, 2, 0], [1, 3, 1]]),  # 14

        draw_line([[1, 3, 21]]),  # 15
    ]

    @staticmethod
    def third_floor_event():

        GameMap.game_event[14][12] = Monster(x_position=14, y_position=12, monster_attribute=monster_data[0])
        GameMap.game_event[13][9] = Monster(x_position=13, y_position=9, monster_attribute=monster_data[0])
        GameMap.game_event[18][7] = Monster(x_position=18, y_position=7, monster_attribute=monster_data[0])
        GameMap.game_event[8][5] = Monster(x_position=8, y_position=5, monster_attribute=monster_data[2])
        GameMap.game_event[8][7] = Monster(x_position=8, y_position=7, monster_attribute=monster_data[2])
        GameMap.game_event[8][8] = Monster(x_position=8, y_position=8, monster_attribute=monster_data[2])
        GameMap.game_event[8][11] = Monster(x_position=8, y_position=11, monster_attribute=monster_data[2])
        GameMap.game_event[9][2] = Monster(x_position=9, y_position=2, monster_attribute=monster_data[3])
        GameMap.game_event[10][3] = Monster(x_position=10, y_position=3, monster_attribute=monster_data[3])
        GameMap.game_event[13][3] = Monster(x_position=13, y_position=3, monster_attribute=monster_data[3])
        GameMap.game_event[12][3] = Monster(x_position=12, y_position=3, monster_attribute=monster_data[3])
        GameMap.game_event[16][10]= Monster(x_position=16, y_position=10, monster_attribute=monster_data[3])

        GameMap.game_event[18][5] = Monster(x_position=18, y_position=5, monster_attribute=monster_data[2])
        GameMap.game_event[17][5] = Monster(x_position=17, y_position=5, monster_attribute=monster_data[2])
        GameMap.game_event[17][6] = Monster(x_position=17, y_position=6, monster_attribute=monster_data[5])
        GameMap.game_event[13][6] = Key(x_position=13, y_position=6, color="red")
        GameMap.game_event[13][5] = Key(x_position=13, y_position=5, color="purple")
        GameMap.game_event[14][5] = Key(x_position=14, y_position=5, color="purple")
        GameMap.game_event[14][6] = Key(x_position=14, y_position=6, color="yellow")

        GameMap.game_event[18][4] = Door(x_position=18, y_position=4, color="purple")
        GameMap.game_event[15][10] = Door(x_position=15, y_position=10, color="yellow")
        GameMap.game_event[19][9] = Door(x_position=19, y_position=9, color="yellow")
        GameMap.game_event[17][11] = Medicine(x_position=17, y_position=11, color="purple")
        GameMap.game_event[17][10] = Medicine(x_position=17, y_position=10, color="red")
        GameMap.game_event[16][11] = Gem(x_position=16, y_position=11, color="purple")
        GameMap.game_event[7][5] = Key(x_position=7, y_position=5, color="yellow")
        GameMap.game_event[11][7] = Medicine(x_position=11, y_position=7, color="purple")
        GameMap.game_event[11][8] = Medicine(x_position=11, y_position=8, color="red")
        GameMap.game_event[11][10] = Gem(x_position=11, y_position=10, color="red")
        GameMap.game_event[11][11] = Gem(x_position=11, y_position=11, color="purple")
        GameMap.game_event[10][10] = Gem(x_position=10, y_position=10, color="red")
        GameMap.game_event[10][11] = Gem(x_position=10, y_position=11, color="purple")
        GameMap.game_event[9][10] = Stairs(x_position=9, y_position=10, direction=-1, location=[8, 13])
        GameMap.game_event[7][2] = Stairs(x_position=7, y_position=2, direction=1, location=[19,12])

    fourth_floor = [
        draw_line([[1, 3, 21]]),  # 1

        draw_line(head + [[0,-1,3], [1, 1, 1],[0,-1,5], [1, 1, 1],[0,-1,3], [1, 3, 1]]),  # 2开始

        draw_line(head + [[0, -1, 1], [1, 1, 1], [0, -1, 1], [1, 1, 1],  [0, -1, 5], [1, 1, 1],[0, -1, 1], [1, 1, 1],[0, -1, 1],
                          [1, 3, 1]]),  # 3
        draw_line(head + [[0, -1, 1], [1, 1, 1], [0, -1, 1], [1, 1, 1],  [0, -1, 0],[1, 1, 2],[0, -1, 1], [1, 1, 3],[0, -1, 1], [1, 1, 1],[0, -1, 1],
                          [1, 3, 1]]),  # 4
        draw_line(head + [[0, -1, 1], [1, 1, 1], [0, -1, 1], [1, 1, 1],  [0, -1, 5], [1, 1, 1],[0, -1, 1], [1, 1, 1],[0, -1, 1],
                          [1, 3, 1]]),  # 5
        draw_line(head + [[0, -1, 1], [1, 1, 1], [0, -1, 1], [1, 1, 1], [0, -1, 5], [1, 1, 1], [0, -1, 1], [1, 1, 1],[0, -1, 1],
                          [1, 3, 1]]),  # 7
        draw_line(head + [[0, -1, 1], [1, 1, 1], [0, -1, 1], [1, 1, 1],  [0, -1, 0],[1, 1, 2],[0, -1, 1], [1, 1, 3], [0, -1, 1],[1, 1, 1],[0, -1, 1],
                          [1, 3, 1]]),  # 6
        draw_line( [[1, 3, 7], [0, -1, 1], [1, 1, 1], [0, -1, 1], [1, 1, 1], [0, -1, 5], [1, 1, 1], [0, -1, 1], [1, 1, 1], [0, -1, 1],
             [1, 3, 1]]),  # 9
        draw_line(head + [[0, -1, 1], [1, 1, 1], [0, -1, 1], [1, 1, 1],  [0, -1, 5], [1, 1, 1],[0, -1, 1], [1, 1, 1],[0, -1, 1],
                          [1, 3, 1]]),  # 10
        draw_line(head + [[0, -1, 1], [1, 1, 1], [0, -1, 1], [1, 1, 1],  [0, -1, 0], [1, 1, 2],[0, -1, 1], [1, 1, 3],[0, -1, 1],[1, 1, 1],[0, -1, 1],
                          [1, 3, 1]]),  # 8

        draw_line(head + [[0, -1, 1], [1, 1, 1], [0, -1, 1], [1, 1, 1],  [0, -1, 5], [1, 1, 1],[0, -1, 1], [1, 1, 1],[0, -1, 1],
                          [1, 3, 1]]),  # 11
        draw_line(head + [[0, -1, 1], [1, 1, 1], [0, -1, 1], [1, 1, 1],  [0, -1, 5], [1, 1, 1],[0, -1, 1], [1, 1, 1],[0, -1, 1],
                          [1, 3, 1]]),
        # 12
        draw_line(head + [[0, -1, 1], [1, 1, 1], [0, -1, 1], [1, 1, 1],  [0, -1, 5], [1, 1, 1],[0, -1, 1], [1, 1, 1],[0, -1, 1],
                          [1, 3, 1]]),  # 13
        draw_line(head + [[0, -1, 1], [1, 1, 1],[0, -1, 1],[0, -1, 8],[1, 1, 1],[0, -1, 1], [1, 3, 1]]),  # 14

        draw_line([[1, 3, 21]]),  # 15
    ]
    @staticmethod
    def fourth_floor_event():

        GameMap.game_event[7][13] = Stairs(x_position=7, y_position=13, direction=1, location=[7, 3])
        GameMap.game_event[19][13] = Stairs(x_position=19, y_position=13, direction=-1, location=[7, 3])


        GameMap.game_event[12][8] = Monster(x_position=12, y_position=8, monster_attribute=monster_data[3])
        GameMap.game_event[13][5] = Monster(x_position=13, y_position=5, monster_attribute=monster_data[1])
        GameMap.game_event[14][5] = Monster(x_position=14, y_position=5, monster_attribute=monster_data[3])
        GameMap.game_event[12][5] = Monster(x_position=12, y_position=5, monster_attribute=monster_data[2])
        GameMap.game_event[13][4] = Monster(x_position=13, y_position=4, monster_attribute=monster_data[5])
        GameMap.game_event[14][4] = Monster(x_position=14, y_position=4, monster_attribute=monster_data[2])
        GameMap.game_event[12][4] = Monster(x_position=12, y_position=4, monster_attribute=monster_data[2])
        GameMap.game_event[13][7] = Monster(x_position=13, y_position=7, monster_attribute=monster_data[3])
        GameMap.game_event[12][7] = Monster(x_position=12, y_position=7, monster_attribute=monster_data[3])
        GameMap.game_event[14][7] = Monster(x_position=14, y_position=7, monster_attribute=monster_data[3])
        GameMap.game_event[13][8] = Monster(x_position=13, y_position=8, monster_attribute=monster_data[3])
        GameMap.game_event[14][8] = Monster(x_position=14, y_position=8, monster_attribute=monster_data[3])

        GameMap.game_event[19][5] = Monster(x_position=19, y_position=5, monster_attribute=monster_data[0])
        GameMap.game_event[17][5] = Monster(x_position=17, y_position=5, monster_attribute=monster_data[3])
        GameMap.game_event[17][6] = Monster(x_position=17, y_position=6, monster_attribute=monster_data[6])

        GameMap.game_event[13][2] = Key(x_position=13, y_position=2, color="red")
        GameMap.game_event[14][2] = Key(x_position=14, y_position=2, color="purple")
        GameMap.game_event[12][2] = Key(x_position=12, y_position=2, color="purple")
        GameMap.game_event[15][10] = Key(x_position=15, y_position=10, color="yellow")
        GameMap.game_event[11][10] = Key(x_position=11, y_position=10, color="purple")
        GameMap.game_event[7][5] = Key(x_position=7, y_position=5, color="yellow")

        GameMap.game_event[13][3] = Door(x_position=13, y_position=3, color="red")
        GameMap.game_event[13][9] = Door(x_position=13, y_position=9, color="purple")
        GameMap.game_event[7][2] = Door(x_position=7, y_position=2, color="yellow")
        GameMap.game_event[9][2] = Door(x_position=9, y_position=2, color="yellow")
        GameMap.game_event[13][6] = Door(x_position=13, y_position=6, color="yellow")

        GameMap.game_event[11][7] = Medicine(x_position=11, y_position=7, color="purple")
        GameMap.game_event[15][7] = Medicine(x_position=15, y_position=7, color="red")
        GameMap.game_event[11][8] = Medicine(x_position=11, y_position=8, color="purple")
        GameMap.game_event[15][8] = Medicine(x_position=15, y_position=8, color="purple")

        GameMap.game_event[15][11] = Gem(x_position=15, y_position=11, color="purple")
        GameMap.game_event[13][1] = Gem(x_position=13, y_position=1, color="red")
        GameMap.game_event[14][1] = Gem(x_position=14, y_position=1, color="purple")
        GameMap.game_event[12][1] = Gem(x_position=12, y_position=1, color="red")
        GameMap.game_event[11][11] = Gem(x_position=11, y_position=11, color="purple")
        GameMap.game_event[15][5] = Gem(x_position=15, y_position=5, color="purple")
        GameMap.game_event[15][4] = Gem(x_position=15, y_position=4, color="red")
        GameMap.game_event[11][5] = Gem(x_position=11, y_position=5, color="purple")
        GameMap.game_event[11][4] = Gem(x_position=11, y_position=4, color="red")

    # print(first_floor)
    map_list = [first_floor,second_floor,third_floor,fourth_floor]
    event_list = ['first_floor_event','second_floor_event','third_floor_event','fourth_floor_event']

    @staticmethod
    def load_map(map_index):
        GameMap.current_floor = map_index
        game_map_data = GameMap.map_list[map_index]
        for i in range(0, len(game_map_data)):
            for j in range(0, len(game_map_data[i])):
                print(GameMap.map_data_dictionary[game_map_data[i][j][0]][0])
                GameMap.game_map[j][i] = GameMap.map_data_dictionary[game_map_data[i][j][0]][0](x_position=j,
                                                                                                y_position=i)
                GameMap.map_data_dictionary[game_map_data[i][j][0]][1](img_type=game_map_data[i][j][1], x_position=j,
                                                                       y_position=i)
        GameMap.__dict__[GameMap.event_list[map_index]].__func__()
